import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chat/common/constant/constants.dart';
import 'package:flutter_chat/common/style/styles.dart';
import 'package:flutter_chat/common/widget/widgets.dart';
import 'package:flutter_chat/pages/application/pages/contacts/widget/info.dart';
import 'package:get/get.dart';

import 'logic.dart';

class ContactsPage extends GetView<ContactsLogic> {
  const ContactsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return _buildEasyRefresh();
  }

  /// 列表
  ListView _buildListView(ScrollPhysics physics) {
    return ListView(
      physics: physics,
      children: [
        _buildUserGroup(),
        const SizedBox(height: AppTheme.largeSpace),
        _buildUser(),
      ],
    );
  }

  /// 群聊
  Info _buildUserGroup() {
    return Info(
      onTap: () {
        Get.toNamed(RouterName.groupList);
      },
      avatar: Container(
        width: 35,
        height: 35,
        decoration: BoxDecoration(
          color: Colors.green,
          borderRadius: BorderRadius.circular(
            AppTheme.radius,
          ),
        ),
        child: const Icon(
          Icons.group_rounded,
          color: Colors.white,
        ),
      ),
      title: '群聊',
    );
  }

  /// 用户
  Widget _buildUser() {
    return Info(
      onTap: () {
        Get.toNamed("${RouterName.userHome}/2327972001");
      },
      avatar: const ImageWidget(
        "http://q1.qlogo.cn/g?b=qq&nk=2327972001&s=640",
        size: 35,
        radius: AppTheme.radius,
      ),
      title: '闲谈',
    );
  }

  /// 下拉刷新
  EasyRefresh _buildEasyRefresh() {
    return EasyRefresh.builder(
      header: CustomClassic().getHeader(),
      footer: CustomClassic().getFooter(),
      onRefresh: () async {
        await Future.delayed(const Duration(seconds: 2));
      },
      childBuilder: (context, physics) {
        return _buildListView(physics);
      },
    );
  }
}
